CFLAGS = -Wall -ggdb
OBJS =  main.o tiger-gram.o lex.yy.o
SRCHOME = src
BLDHOME = build
BINHOME = bin
INCHOME = include
LIBHOME = lib
PROG = tigerc

all: $(OBJS)
	gcc  -o ${PROG} $(OBJS) -lfl
	mv *.o ${BLDHOME}/
	mv *.c ${SRCHOME}/
	mv *.h ${INCHOME}/
	mv ${PROG} ${BINHOME}/

lex.yy.c: ${LIBHOME}/tiger-lex.l
	flex $<

tiger-gram.c: ${LIBHOME}/tiger-gram.y
	bison -tdvl -o tiger-gram.c ${LIBHOME}/tiger-gram.y

main.o: ${SRCHOME}/main.c
	gcc -I${INCHOME}/ $(CFLAGS) -c $<

lex.yy.o: lex.yy.c
	gcc -I${INCHOME}/ $(CFLAGS) -c $<

tiger-gram.o: tiger-gram.c
	gcc -I${INCHOME}/ $(CFLAGS) -c $<

clean:
	rm -f *~
	rm -f *.output
	rm ${SRCHOME}/tiger-gram.c
	rm ${INCHOME}/tiger-gram.h
	rm ${SRCHOME}/lex.yy.c
	rm ${BLDHOME}/*.o
	rm ${BINHOME}/${PROG}
